Public Class Listener
    Inherits WebControls.WebControl

    Private m_sEvent As String
    Private m_sHandler As String

    Public Property [Event]() As String
        Get
            Return m_sEvent
        End Get
        Set(ByVal value As String)
            m_sEvent = value
        End Set
    End Property

    Public Property Handler() As String
        Get
            Return m_sHandler
        End Get
        Set(ByVal value As String)
            m_sHandler = value
        End Set
    End Property

    Public Sub New()
        MyBase.New()

        ID = Common.GetUniqueID(Context)
    End Sub

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        'Do Nothing
    End Sub

    Private Sub Listener_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Dim sbListener As New Text.StringBuilder

        With sbListener
            .Append("$(window).bind('load',null,function() {AddListener('")
            .Append([Event])
            .Append("','")
            .Append(Handler)
            .Append("')});")
        End With

        ScriptManager.RegisterStartupScript(Me, Me.GetType, ID, sbListener.ToString(), True)
    End Sub
End Class